﻿using System.Text;
using Sanelib.Common.SystemSettings;

namespace Sanelib.CodeMaker.Generators
{
    public class FormGenerator
    {
        public static void Generate(DatabaseTableSchema tbSchema)
        {
            var sb = new StringBuilder();

            sb.AppendLine("using Sanelib.Dto.ApiRequests;");
            sb.AppendLine("");
            sb.AppendLine("namespace Dto.ApiRequests");
            sb.AppendLine("{");
            sb.AppendLine("\tpublic class Add" + tbSchema.TableName + "Form : FormBase");
            sb.AppendLine("\t{");
            
            foreach (var item in tbSchema.Columns)
            {
                sb.AppendLine(item.GetPropertyDeclaration("\t\t"));
            }
            
            sb.AppendLine("");
            sb.AppendLine("\t\tpublic override string GetCommandValue()");
            sb.AppendLine("\t\t{");
            sb.AppendLine("\t\t\tthrow new System.NotImplementedException();");
            sb.AppendLine("\t\t}");
            sb.AppendLine("");

            sb.AppendLine("\t\tpublic override string GetApiAddress()");
            sb.AppendLine("\t\t{");
            sb.AppendLine("\t\t\tthrow new System.NotImplementedException();");
            sb.AppendLine("\t\t}");

            sb.AppendLine("\t}");
            sb.AppendLine("}");

            sb.AppendLine("");

            sb.AppendLine("\tpublic class Update" + tbSchema.TableName + ": Add" + tbSchema.TableName);
            sb.AppendLine("\t{");
            sb.AppendLine("");
            sb.AppendLine("\t}");

            sb.AppendLine("");
            

            System.IO.File.WriteAllText(Globals.CreateOrGetCustomPath("..\\Dto\\ApiRequests\\") + tbSchema.TableName + "Form_Generated.cs", sb.ToString());
        }
    }
}
